package schema

import (
	"github.com/shopspring/decimal"
	"lianzi_gos/internal/config"
	"lianzi_gos/pkg/util"
	"time"
)

// 小程序用户端
type Member struct {
	ID             string          `json:"id" gorm:"size:20;primarykey;"` // Unique ID
	Uniqid         string          `json:"uniqid"  gorm:"size:50;comment:'用户唯一值'"`
	Openid         string          `json:"openid"  gorm:"size:50;comment:'用户openid'"`
	RealName       string          `json:"real_name"  gorm:"size:30;comment:'真实姓名';default:''"`
	Nickname       string          `json:"nickname"  gorm:"size:30;comment:'昵称';default:''"`
	Avatar         string          `json:"avatar"  gorm:"size:200;comment:'头像';default:''"`
	Phone          string          `json:"phone"  gorm:"size:20;index;comment:'手机号';default:''"`
	Pid            string          `json:"pid"  gorm:"size:20;index;comment:'推荐人';default:''"`
	NowMoney       decimal.Decimal `json:"now_money" gorm:"type:decimal(10,2);not null;comment:'用户余额';default:0"`
	BrokeragePrice decimal.Decimal `json:"brokerage_price" gorm:"type:decimal(10,2);not null;index;comment:'佣金金额';default:0"`
	Integral       int64           `json:"integral" gorm:"comment:'积分';index;default:0"`
	UserType       string          `json:"user_type"  gorm:"size:20;index;comment:'用户登陆类型，h5,wechat,routine';default:''"`
	Status         string          `json:"status" gorm:"size:20;index;comment:'enabled, disabled';default:'enabled'"` // Status of  (enabled, disabled)
	Mark           string          `json:"mark" gorm:"size:200;index;comment:'备注';default:''"`                        // Status of  (enabled, disabled)
	CreatedAt      time.Time       `json:"created_at" gorm:"index;"`                                                  // Create time
	UpdatedAt      time.Time       `json:"updated_at" gorm:"index;"`                                                  // Update time
	IsAuth         bool            `json:"is_auth" gorm:"-"`                                                          // Update time
	IsAdmin        bool            `json:"is_admin" gorm:"-"`                                                         // Update time
}

func (a *Member) TableName() string {
	return config.C.FormatTableName("member")
}

// 登录后 返回给用户端
type MiniWxRes struct {
	Token    string
	UserInfo Member
	Status   int
	Auth     bool
}

// Defining the query parameters for the `Member` struct.
type MemberQueryParam struct {
	//LikeUserType string `form:"user_type"` // UserType
	LikeNickname string `form:"nickname"` // Username for login
	util.PaginationParam
}

// Defining the query options for the `Member` struct.
type MemberQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Member` struct.
type MemberQueryResult struct {
	Data       Members
	PageResult *util.PaginationResult
}

// Defining the slice of `Member` struct.
type Members []*Member

// Defining the data structure for creating a `Member` struct.
type MemberForm struct {
}

// A validation function for the `MemberForm` struct.
func (a *MemberForm) Validate() error {
	return nil
}

// Convert `MemberForm` to `Member` object.
func (a *MemberForm) FillTo(member *Member) error {
	return nil
}

type MiniWechatForm struct {
	Code string
}

// A validation function for the `MemberForm` struct.
func (a *MiniWechatForm) Validate() error {
	return nil
}

type UpdatePhone struct {
	Phone string `json:"phone" binding:"required"` // 手机号
}
type UpdateNicknameAvatar struct {
	Nickname string `json:"nickname" binding:"required"` // 昵称
	Avatar   string `json:"avatar" binding:"required"`   //头像
}
